//  https://www.luogu.com.cn/problem/P1880

#include<iostream>
#include<cstring>
using namespace std;

const int N = 210;
int sum[N];
int dp1[N][N], dp2[N][N];

int main()
{
    int n;cin >> n;
    for (int i = 1;i <= n;i++)
    {
        cin >> sum[i];
        sum[i + n] = sum[i];
    }
    int m = n + n;
    for (int i = 1;i <= m;i++)
        sum[i] += sum[i - 1];

    memset(dp1, 0x3f, sizeof dp1);
    memset(dp2, -0x3f, sizeof dp2);

    for (int i = 1;i <= m;i++)
        dp1[i][i] = dp2[i][i] = 0;

    for (int len = 1;len <= m;len++)
        for (int i = 1;i + len - 1 <= m;i++)
        {
            int j = i + len - 1;
            for (int k = i;k < j;k++)
            {
                dp1[i][j] = min(dp1[i][j], dp1[i][k] + dp1[k + 1][j] + sum[j] - sum[i - 1]);
                dp2[i][j] = max(dp2[i][j], dp2[i][k] + dp2[k + 1][j] + sum[j] - sum[i - 1]);
            }
        }

    int ret1 = 0x3f3f3f3f, ret2 = -0x3f3f3f3f;
    for (int i = 1;i <= n;i++)
    {
        ret1 = min(ret1, dp1[i][i + n - 1]);
        ret2 = max(ret2, dp2[i][i + n - 1]);
    }
    cout << ret1 << endl << ret2;
    return 0;
}